home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JSplitPane;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.SplitPaneUI;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.awt.peer.ComponentPeer;
- import java.awt.peer.LightweightPeer;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.io.Serializable;
- import java.util.EventObject;
-
- public class BasicSplitPaneUI extends SplitPaneUI implements PropertyChangeListener, Serializable {
- protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider";
- protected JSplitPane splitPane;
- private int orientation;
- protected BasicHorizontalLayoutManager layoutManager;
- private boolean continuousLayout;
- protected BasicSplitPaneDivider divider;
- private int lastDragLocation;
- protected int dividerSize;
- protected Component nonContinuousLayoutDivider;
- protected boolean draggingHW;
- protected int beginDragDividerLocation;
-
- public BasicSplitPaneUI() {
- this.setLastDragLocation(-1);
- }
-
- public BasicSplitPaneDivider createDefaultDivider() {
- return new BasicSplitPaneDivider(this);
- }
-
- protected Component createDefaultNonContinuousLayoutDivider() {
- return new 1(this);
- }
-
- public static ComponentUI createUI(JComponent x) {
- return new BasicSplitPaneUI();
- }
-
- protected void dragDividerTo(int location) {
- if (this.getLastDragLocation() != location) {
- if (this.isContinuousLayout()) {
- Component leftC = this.splitPane.getLeftComponent();
- Rectangle leftBounds = leftC.getBounds();
- if (this.orientation == 1) {
- leftC.setSize(location - leftBounds.x, leftBounds.height);
- } else {
- leftC.setSize(leftBounds.width, location - leftBounds.y);
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- this.setLastDragLocation(location);
- } else {
- int lastLoc = this.getLastDragLocation();
- this.setLastDragLocation(location);
- if (this.orientation == 1) {
- int splitHeight = this.splitPane.getSize().height;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(this.getLastDragLocation(), 0);
- } else {
- this.splitPane.repaint(lastLoc, 0, this.dividerSize, splitHeight);
- this.splitPane.repaint(location, 0, this.dividerSize, splitHeight);
- }
- } else {
- int splitWidth = this.splitPane.getSize().width;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, this.getLastDragLocation());
- } else {
- this.splitPane.repaint(0, lastLoc, splitWidth, this.dividerSize);
- this.splitPane.repaint(0, location, splitWidth, this.dividerSize);
- }
- }
- }
- }
-
- }
-
- protected void finishDraggingTo(int location) {
- this.dragDividerTo(location);
- this.setLastDragLocation(-1);
- if (!this.isContinuousLayout()) {
- Component leftC = this.splitPane.getLeftComponent();
- Rectangle leftBounds = leftC.getBounds();
- if (this.orientation == 1) {
- int splitHeight = this.splitPane.getSize().height;
- leftC.setSize(location - leftBounds.x, leftBounds.height);
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(-this.dividerSize, 0);
- }
-
- this.splitPane.paintImmediately(location, 0, this.dividerSize, splitHeight);
- } else {
- int splitWidth = this.splitPane.getSize().width;
- leftC.setSize(leftBounds.width, location - leftBounds.y);
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, -this.dividerSize);
- }
-
- this.splitPane.paintImmediately(0, location, splitWidth, this.dividerSize);
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- this.splitPane.setLastDividerLocation(this.beginDragDividerLocation);
- }
-
- public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
- if (jc == this.splitPane && this.getLastDragLocation() != -1 && !this.isContinuousLayout() && !this.draggingHW) {
- Dimension size = this.splitPane.getSize();
- g.setColor(Color.darkGray);
- if (this.orientation == 1) {
- g.fillRect(this.getLastDragLocation(), 0, this.dividerSize - 1, size.height - 1);
- } else {
- g.fillRect(0, this.lastDragLocation, size.width - 1, this.dividerSize - 1);
- }
- }
-
- }
-
- public BasicSplitPaneDivider getDivider() {
- return this.divider;
- }
-
- protected int getDividerBorderSize() {
- return 1;
- }
-
- public int getDividerLocation() {
- return this.orientation == 1 ? this.divider.getLocation().x : this.divider.getLocation().y;
- }
-
- public Insets getInsets(JComponent jc) {
- return null;
- }
-
- public int getLastDragLocation() {
- return this.lastDragLocation;
- }
-
- public int getMaximumDividerLocation() {
- Dimension splitPaneSize = this.splitPane.getSize();
- int maxLoc = 0;
- Component rightC = this.splitPane.getRightComponent();
- if (rightC != null) {
- Insets insets = this.splitPane.getInsets();
- Dimension minSize = rightC.getMinimumSize();
- if (this.orientation == 1) {
- maxLoc = splitPaneSize.width - minSize.width;
- } else {
- maxLoc = splitPaneSize.height - minSize.height;
- }
-
- maxLoc -= this.dividerSize + this.getDividerBorderSize();
- if (insets != null) {
- if (this.orientation == 1) {
- maxLoc += insets.left;
- } else {
- maxLoc += insets.top;
- }
- }
- }
-
- return Math.max(this.getMinimumDividerLocation(), maxLoc);
- }
-
- public Dimension getMaximumSize(JComponent jc) {
- return this.splitPane != null ? this.layoutManager.maximumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public int getMinimumDividerLocation() {
- int minLoc = 0;
- Component leftC = this.splitPane.getLeftComponent();
- if (leftC != null) {
- Insets insets = this.splitPane.getInsets();
- Dimension minSize = leftC.getMinimumSize();
- if (this.orientation == 1) {
- minLoc = minSize.width;
- } else {
- minLoc = minSize.height;
- }
-
- minLoc += this.getDividerBorderSize();
- if (insets != null) {
- if (this.orientation == 1) {
- minLoc += insets.left;
- } else {
- minLoc += insets.top;
- }
- }
- }
-
- return minLoc;
- }
-
- public Dimension getMinimumSize(JComponent jc) {
- return this.splitPane != null ? this.layoutManager.minimumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public Component getNonContinuousLayoutDivider() {
- return this.nonContinuousLayoutDivider;
- }
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public Dimension getPreferredSize(JComponent jc) {
- return this.splitPane != null ? this.layoutManager.preferredLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public JSplitPane getSplitPane() {
- return this.splitPane;
- }
-
- protected void installDefaults(JComponent c) {
- this.splitPane = (JSplitPane)c;
- LookAndFeel.installBorder(c, "SplitPane.border");
- if (this.divider == null) {
- this.divider = this.createDefaultDivider();
- }
-
- this.divider.setBasicSplitPaneUI(this);
- this.splitPane.setDividerSize((Integer)UIManager.get("SplitPane.dividerSize"));
- this.divider.setDividerSize(this.splitPane.getDividerSize());
- this.splitPane.add(this.divider, "divider");
- this.setOrientation(this.splitPane.getOrientation());
- this.setContinuousLayout(this.splitPane.isContinuousLayout());
- this.resetLayoutManager();
- if (this.nonContinuousLayoutDivider == null) {
- this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
- } else {
- this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
- }
-
- }
-
- protected void installListeners(JComponent c) {
- this.splitPane.addPropertyChangeListener(this);
- }
-
- public void installUI(JComponent c) {
- this.installDefaults(c);
- this.installListeners(c);
- this.splitPane.layout();
- }
-
- public boolean isContinuousLayout() {
- return this.continuousLayout;
- }
-
- public void paint(Graphics g, JComponent jc) {
- }
-
- public void propertyChange(PropertyChangeEvent e) {
- if (((EventObject)e).getSource() == this.splitPane) {
- String changeName = e.getPropertyName();
- if (changeName.equals("orientation")) {
- this.orientation = this.splitPane.getOrientation();
- this.resetLayoutManager();
- } else if (changeName.equals("continuousLayout")) {
- this.setContinuousLayout(this.splitPane.isContinuousLayout());
- if (!this.isContinuousLayout()) {
- if (this.nonContinuousLayoutDivider == null) {
- this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
- } else if (this.nonContinuousLayoutDivider.getParent() == null) {
- this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
- }
- }
- } else if (changeName.equals("dividerSize")) {
- this.divider.setDividerSize(this.splitPane.getDividerSize());
- this.layoutManager.resetSizeAt(2);
- this.splitPane.invalidate();
- this.splitPane.validate();
- }
- }
-
- }
-
- protected void resetLayoutManager() {
- if (this.orientation == 1) {
- this.layoutManager = new BasicHorizontalLayoutManager(this);
- } else {
- this.layoutManager = new BasicVerticalLayoutManager(this);
- }
-
- this.splitPane.setLayout(this.layoutManager);
- this.layoutManager.updateComponents();
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- public void resetToPreferredSizes() {
- if (this.splitPane != null) {
- this.layoutManager.resetToPreferredSizes();
- this.splitPane.validate();
- this.layoutManager.layoutContainer(this.splitPane);
- }
-
- }
-
- public void setContinuousLayout(boolean b) {
- this.continuousLayout = b;
- }
-
- public void setDividerLocation(int location) {
- Component leftC = this.splitPane.getLeftComponent();
- Component rightC = this.splitPane.getRightComponent();
- if (leftC != null && rightC != null) {
- Insets insets = this.splitPane.getInsets();
- if (insets != null) {
- if (this.orientation == 1) {
- leftC.setSize(Math.max(0, location - insets.left), 10);
- } else {
- leftC.setSize(10, Math.max(0, location - insets.top));
- }
- } else if (this.orientation == 1) {
- leftC.setSize(Math.max(0, location), 10);
- } else {
- leftC.setSize(10, Math.max(0, location));
- }
-
- this.splitPane.validate();
- this.splitPane.repaint();
- }
-
- }
-
- public void setLastDragLocation(int l) {
- this.lastDragLocation = l;
- }
-
- protected void setNonContinuousLayoutDivider(Component newDivider) {
- this.setNonContinuousLayoutDivider(newDivider, true);
- }
-
- protected void setNonContinuousLayoutDivider(Component newDivider, boolean rememberSizes) {
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- this.nonContinuousLayoutDivider = newDivider;
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.nonContinuousLayoutDivider.setLocation(-1000, -1000);
- Component leftC = this.splitPane.getLeftComponent();
- Component rightC = this.splitPane.getRightComponent();
- int[] sizes = this.layoutManager.getSizes();
- if (leftC != null) {
- this.splitPane.setLeftComponent((Component)null);
- }
-
- if (rightC != null) {
- this.splitPane.setRightComponent((Component)null);
- }
-
- this.splitPane.remove(this.divider);
- this.splitPane.add(this.nonContinuousLayoutDivider, "nonContinuousDivider", this.splitPane.getComponentCount());
- this.splitPane.setLeftComponent(leftC);
- this.splitPane.setRightComponent(rightC);
- this.splitPane.add(this.divider, "divider");
- if (rememberSizes) {
- this.layoutManager.setSizes(sizes);
- }
-
- this.splitPane.validate();
- this.splitPane.paintImmediately(this.splitPane.getX(), this.splitPane.getY(), this.splitPane.getWidth(), this.splitPane.getHeight());
- }
-
- }
-
- public void setOrientation(int orientation) {
- this.orientation = orientation;
- }
-
- protected void startDragging() {
- Component leftC = this.splitPane.getLeftComponent();
- Component rightC = this.splitPane.getRightComponent();
- this.beginDragDividerLocation = this.getDividerLocation();
- this.draggingHW = false;
- ComponentPeer cPeer;
- if (leftC != null && (cPeer = leftC.getPeer()) != null && !(cPeer instanceof LightweightPeer)) {
- this.draggingHW = true;
- } else if (rightC != null && (cPeer = rightC.getPeer()) != null && !(cPeer instanceof LightweightPeer)) {
- this.draggingHW = true;
- }
-
- if (this.orientation == 1) {
- this.setLastDragLocation(this.divider.getBounds().x);
- this.dividerSize = this.divider.getSize().width + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(this.getLastDragLocation(), 0, this.dividerSize, this.splitPane.getHeight());
- }
- } else {
- this.setLastDragLocation(this.divider.getBounds().y);
- this.dividerSize = this.divider.getSize().height + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(0, this.getLastDragLocation(), this.splitPane.getWidth(), this.dividerSize);
- }
- }
-
- }
-
- protected void uninstallDefaults(JComponent c) {
- if (this.splitPane.getLayout() == this.layoutManager) {
- this.splitPane.setLayout((LayoutManager)null);
- }
-
- if (this.nonContinuousLayoutDivider != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- this.splitPane.remove(this.divider);
- this.divider.setBasicSplitPaneUI((BasicSplitPaneUI)null);
- this.splitPane = null;
- this.layoutManager = null;
- this.setNonContinuousLayoutDivider((Component)null);
- }
-
- protected void uninstallListeners(JComponent c) {
- this.splitPane.removePropertyChangeListener(this);
- }
-
- public void uninstallUI(JComponent c) {
- this.uninstallListeners(c);
- this.uninstallDefaults(c);
- }
-
- static int access$orientation(BasicSplitPaneUI var0) {
- return var0.orientation;
- }
- }
-